package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.order.client.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Map;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/9/2 9:37
 * @Version 1.0
 */
@Controller
public class OrderController {

    @Autowired
    private OrderFeignClient orderFeignClient;

    //  http://order.gmall.com/trade.html
    @GetMapping("trade.html")
    public String trade(Model model){
        //  userAddressList 这个key 异步读取， detailArrayList totalNum totalAmount tradeNo 后台要存储
        //  第一种方式：
        //  model.addAttribute("detailArrayList",detailArrayList);
        //  model.addAttribute("totalNum",totalNum);
        //  model.addAttribute("totalAmount",totalAmount);
        //  第二种：
        //  model.addAllAttributes(result.getData());
        Result<Map> result = orderFeignClient.authTrade();
        //  存储数据
        model.addAllAttributes(result.getData());

        //  订单结算页
        return "order/trade";
    }

    //  http://order.gmall.com/myOrder.html
    @GetMapping("myOrder.html")
    public String myOrder(){
        //  返回我的订单页面
        return "order/myOrder";
    }

}
